package com.example.tests;

import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import com.example.utils.SortedListOf;
import static com.example.tests.GroupDataGenerator.loadGroupsToCsvFile;
import static com.example.tests.GroupDataGenerator.loadGroupsToXmlFile;
import static org.junit.Assert.assertThat;
import static org.hamcrest.Matchers.*;

public class GroupCreation extends AddressbookTestBase{	
	
	@DataProvider
	public Iterator<Object[]> groupsFromFile() throws IOException{	
		return wrapGroupsForDataProvider(loadGroupsToXmlFile(new File("groups.xml"))).iterator();		
	}	

	@Test(dataProvider = "groupsFromFile")
	public void testValidDataGroupCreation(GroupData groupInput) throws Exception {
		//save old state
		SortedListOf<GroupData> oldList = app.getGroupHelper().getGroups();
		//actions
		app.getGroupHelper().createGroup(groupInput);
		//save new state
		SortedListOf<GroupData> newList = app.getGroupHelper().getGroups();		
		//compare states	
		assertThat(newList, equalTo(oldList.withAdded(groupInput)));
	}
}
